package sg.edu.nus.iss.ooad.jass.controller;

import java.util.logging.Level;
import java.util.logging.Logger;
import sg.edu.nus.iss.ooad.jass.entity.Advertiser;
import sg.edu.nus.iss.ooad.jass.entity.Jobseeker;
import sg.edu.nus.iss.ooad.jass.entity.LoginInfo;
 

/**
 *
 * Login Controller. This class will handler login and logout process into/from JASS.
 *
 * @author Isak Rabin (HT082193M)
 * @version 1.0
 * @since 1.0
 *
 * Development Environment : Netbeans IDE v6.7
 * Name of the File        : LoginController.java
 * Creation / Modification History
 *         Isak Rabin        20-Sep-2009        Created
 *
 */
public class LoginController {

        private final static Logger logger = Logger.getLogger(LoginController.class.getName());
        
        //Login parameters
        private String userId = "";
        private String password = "";
        private int userDomain = LoginInfo.UNKNOWN;
 
        public LoginController() {
        }

        /**
         *
         * @param userId
         * @param password
         * @param userDomain
         */
        public LoginController(String userId, String password, int userDomain) {
                this.userId = userId;
                this.password = password;
                this.userDomain = userDomain;
        }

        /**
         *
         * @return
         */
        public boolean processLogin() {
                boolean retValue = false;
                try {
                        switch (userDomain) {
                                case LoginInfo.JOBSEEKER:
                                        //JobSeeker Login
                                        JobseekerController jobseekerController = new JobseekerController();
                                        Jobseeker jobseeker = jobseekerController.getJobseekerByEmail(userId);
                                        if (jobseeker != null) {
                                                String dbUserId = jobseeker.getEmail();
                                                String dbPassword = jobseeker.getPassword();
                                                if (dbUserId.equalsIgnoreCase(userId) && dbPassword.equals(password)) {
                                                        retValue = true;
                                                }
                                        }
                                        break;
                                case LoginInfo.JOBADVERTISER:
                                        //Advertiser Login
                                        AdvertiserController advertiserController = new AdvertiserController();
                                        Advertiser advertiser = advertiserController.getAdvertiserByUserID(userId);
                                        if (advertiser != null) {
                                                String dbUserId = advertiser.getUserID();
                                                String dbPassword = advertiser.getPassword();
                                                if (dbUserId.equalsIgnoreCase(userId) && dbPassword.equals(password)) {
                                                        retValue = true;
                                                }
                                        }
                                        break;
                                case LoginInfo.SYSTEMADMINISTRATOR:
                                        //System Administrator Login --> Not Implemented
                                        throw new UnsupportedOperationException("Not supported yet.");
                                default:
                                        throw new UnsupportedOperationException("Invalid Login Domain.");
                        }
                } catch (Exception ex) {
                        logger.log(Level.SEVERE, null, ex);
                        ex.printStackTrace();
                }

                return retValue;
        }

        /**
         *
         * @return
         */
        public boolean processLogout() {
                boolean retValue = false;

                return retValue;
        }
        

        
        
}
